<template>
    <div class="article-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="会员信息">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.name"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="信息分类">
                    <el-select class="w-[280px]" v-model="queryParams.equity">
                        <el-option label="全部" value />
                        <el-option
                            v-for="item in optionsData"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <div>
                <router-link
                    v-perms="['vip.vip/add', 'vip.vip/add:edit']"
                    :to="{
                        path: getRoutePath('vip.vip/add:edit')
                    }"
                >
                    <el-button type="primary" class="mb-4">
                        <template #icon>
                            <icon name="el-icon-Plus" />
                        </template>
                        添加会员信息
                    </el-button>
                </router-link>
            </div>
            <el-table Checkbox="true"
                      type="selection"
                      size="large" v-loading="pager.loading" :data="pager.lists">
				<el-table-column label="会员分类" min-width="100">
				     <template #default="{ row }">
				         <div v-if="row.equity==1">发布信息置顶</div>
										  <div v-if="row.equity==2">查看联系方式</div>
				     </template>
				 </el-table-column>
                <el-table-column label="会员名称" prop="name" min-width="100" />
                <el-table-column label="价格" prop="price" min-width="100" />
				<el-table-column label="画线价格" prop="huaxian" min-width="100" />
				<el-table-column label="到期形式" min-width="100">
				     <template #default="{ row }">
				         <div v-if="row.type==1">
							 查看时间:{{row.vip_time}}天
						 </div>
						<div v-if="row.type==2">
							查看次数:{{row.cishu}}次
						</div>
				     </template>
				 </el-table-column>
				<el-table-column label="详情" prop="title" min-width="200" />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['vip.vip/edit', 'vip.vip/add:edit']"
                            type="primary"
                            link
                        >
                            <router-link
                                :to="{
                                    path: getRoutePath('vip.vip/add:edit'),
                                    query: {
                                        id: row.id
                                    }
                                }"
                            >
                                编辑
                            </router-link>
                        </el-button>
                        <el-button
                            v-perms="['vip.vip/delete']"
                            type="danger"
                            link
                            @click="handleDelete(row.id)"
                        >
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
<script lang="ts" setup name="articleLists">
import { articleLists, articleDelete, articleStatus, articleCateAll,vipLists,vipDelete } from '@/api/article'
import { useDictOptions } from '@/hooks/useDictOptions'
import { usePaging } from '@/hooks/usePaging'
import { getRoutePath } from '@/router'
import feedback from '@/utils/feedback'
const queryParams = reactive({
    name: '',
    equity: '',
    is_show: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: vipLists,
    params: queryParams
})

const optionsData=([{
	id:1,
	name:'发布信息置顶'
},
{
	id:2,
	name:'查看联系方式'
}])

const changeStatus = async (is_show: any, id: number) => {
    try {
        await articleStatus({ id, is_show })
        getLists()
    } catch (error) {
        getLists()
    }
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await vipDelete({ id })
    getLists()
}

onActivated(() => {
    getLists()
})

getLists()
</script>
